package com.aaa.service.impl;


import com.aaa.dao.ForderMapper;
import com.aaa.entity.Forder;
import com.aaa.service.ForderServiceDao;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Random;

import static com.alibaba.nacos.client.naming.utils.RandomUtils.nextInt;

@Service
public class ForderServiceImpl extends ServiceImpl<ForderMapper, Forder> implements ForderServiceDao {
    @Resource
    ForderMapper mapper;
    @Resource
    ForderServiceDao dao;
    @Override
    public List<Forder> selectall(Integer fuser , Integer pageNum, Integer pageSize) {
        return mapper.selectall(fuser,pageNum,pageSize);
    }

    public Integer add(Forder forder){
        Integer add=mapper.insert(forder);
        return add;
    }
    public boolean upadd(Forder forder){
        boolean upadd=dao.saveOrUpdate(forder);
        return upadd;
    }
    @Override
    public Integer update(Integer fuser,Integer id) {
        return mapper.update(fuser,id);
    }
    @Override
    public Integer update1(Integer fuser,Integer id) {

        return mapper.update1(fuser,id);
    }
    @Override
    public Integer fadd(Integer fuser, Integer parcelid, String time, double price, String date,
                        Integer fsite, Integer state, String datetime, String outtradeno)throws ParseException {
        Date date1=new Date();
        SimpleDateFormat sfd=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String now = sfd.format(date1);
        int ca = (int)((Math.random()*9+1)*1000000000+fuser+state);
        Random r = new Random();
       // int z= Math.abs(nextInt(ca));
        parcelid =Math.abs( r.nextInt(10)+ca);
//        Forder.setTime(new Date());
//        String order=new Date().toString()+fOrder.getFUser();
//        Forder.setOutTradeNo(order);

        outtradeno=ca+""+parcelid ;
        fsite=25;
        return mapper.fadd(fuser,parcelid,now,price,now,fsite,state,datetime,outtradeno);
    }
    public List<Forder> max(){
        return mapper.max();
    }
}
